/*
 * @Author: xmily
 * @Date: 2022-03-14 22:01:13
 * @LastEditors: xmily
 * @LastEditTime: 2023-06-05 00:21:07
 * @FilePath: \glxxapi\models\AfterClassService\attendance.js
 * @Description:
 * 考勤记录
 * Copyright (c) 2022 by xmily/mxthink.com.cn, All Rights Reserved.
 */
var mongoose = require("../../cfg/dbconfig.js");
var d = new Date();
var attendanceSchema = new mongoose.Schema(
  {
    term: String,
    schoolname: String,
    date: {
      type: String,
      default:
        d.getFullYear().toString() +
        (d.getMonth() + 1).toString() +
        d.getDate().toString(),
    },
    classno: String,
    shouldNumber: Number,
    realityNumber: Number,
    teacher: String,
    othermem: String,
    mem: [
      {
        option: String,
        number: Number,
        reason: String,
      },
    ],
    attendance:String,
    lessontype:String,
  },
  { collection: "aftclsvr_attendance" }
);

attendanceSchema.statics.Save = async function (doc) {
  let obj = new this(doc);
  if (doc._id) {
    obj.isNew = false;
  }
  let res = await obj.save();
  return res;
};

attendanceSchema.statics.myFindByQuery=async function(query,fields){
    if(fields)
    {
        return await this.find(query,fields).exec()
    }
    return await this.find(query).exec()
}

attendanceSchema.statics.GetOneByQuery = async function (query) {
  let result = await this.findOne(query).exec();
  return result;
};

module.exports = mongoose.model("aftclsvr_attendance", attendanceSchema);
